/**
 * This file is part of iSecurePasswords.
 *
 *   iSecurePasswords is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   iSecurePasswords is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with iSecurePasswords.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author: Matthew MacGregor
 * Created: 2012
 * iSecurePasswords, copyright 2013 Sudolink, LLC
 * 
 */ 
package com.sudolink.isp.ui.menu;

import com.sudolink.isp.app.DesktopManager;
import com.sudolink.isp.media.HelperMethods;
import com.sudolink.isp.media.ResourceConstants;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

/**
 *
 * @author dev
 */
public class GoToUrl extends JMenuItem {
    
    private String url;
    
    private static void log( String message, Throwable ex ) {
        Logger.getLogger(GoToUrl.class.getName()).log(Level.INFO, message, ex);
    }
    
    public GoToUrl(String url) {
        super("Go To Url");
        Icon icon =  HelperMethods.getIconResource(ResourceConstants.WORLD_ICON);
        setIcon(icon);
        this.url = url;
        addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {                
                    try {
                        DesktopManager dm = new DesktopManager();
                        URI uri = new URI(GoToUrl.this.url);
                        dm.browse(uri);
                    } catch ( IOException | URISyntaxException ex) {
                        JOptionPane.showMessageDialog(GoToUrl.this, "The url is not valid.");
                    }

                
            }
        });
    }
    
}
